﻿using DevExpress.XtraEditors.Controls;
using RecruitStudents.Client.BLL;
using RecruitStudents.Utility;
using RecruitStudents.Utility.Const;
using RecruitStudents.Utility.Helper;
using RecruitStudents.Utility.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RecruitStudents.Client.Base
{
    public partial class Base_Mac_Option : BaseForm
    {
        string MacID = string.Empty;
        ServiceBase service = new ServiceBase();
        TB_Exam_Mac model = null;
        public Base_Mac_Option(string strMacID)
        {
            InitializeComponent();
            MacID = strMacID;
            this.cmbType.Properties.NullText = "";
            this.cmbType.Properties.Columns.Add(new LookUpColumnInfo("Key", 30, "编号"));
            this.cmbType.Properties.Columns.Add(new LookUpColumnInfo("Value", 55, "类型"));
            this.cmbType.Properties.DataSource = ConstAppConfig.DicPadType.ToList();
            this.cmbType.Properties.DisplayMember = "Value";
            this.cmbType.Properties.ValueMember = "Key";
            if (MacID.ToSafeString().Length > 0)
            {
                model = service.GetExamMacModel(MacID);
                if (model != null)
                {
                    model.Attach();
                    txtMacNo.Text = model.MacNO;
                    txtMachineName.Text = model.MachineName;
                    txtRemark.Text = model.Remark;
                    cmbType.EditValue = model.MachineType;
                    if (model.IsActive == "1")
                    {
                        chkSFTY.Checked = true;
                    }
                    else
                    {
                        chkSFTY.Checked = false;
                    }

                }
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtMacNo.Text.ToSafeString().Length == 0)
            {
                DevHelper.ShowInfoMessageBox("请先输入设备编号!");
                this.txtMacNo.Focus();
                return;
            }
            //if (txtMachineName.Text.ToSafeString().Length == 0)
            //{
            //    DevHelper.ShowInfoMessageBox("请先输入机器名称!");
            //    this.txtMachineName.Focus();
            //    return;
            //} 
            if (cmbType.Text == "" || cmbType.EditValue == null || cmbType.EditValue.ToSafeString().Length == 0)
            {
                DevHelper.ShowInfoMessageBox("请先选择设备类型!");
                this.cmbType.Focus();
                return;
            }
            if (model == null)
            {
                model = new TB_Exam_Mac();               
            }
            model.IsActive = chkSFTY.Checked ? "1" : "0";
            model.MacNO = txtMacNo.Text;
            //model.MachineName = txtMachineName.Text;           
            model.MachineType = cmbType.EditValue.ToSafeString();
            model.ExamYear = SessionerHelper.SystemYear;
            if (service.SaveExamMac(model))
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }

        private void btnConcal_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
